package edu.sctu.practice.class02.hujie.my_practice.day20151119collection;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;

/**
 * Created by hp on 2015/12/4
 */
public class Test {


    //随机产生的一个十位字符串方法
    public static String getRandomString(int length) { //length表示生成字符串的长度
        List<String> stringList = new ArrayList<String>();
        String base = "abcdefghijklmnopqrstuvwxyz0123456789";
        Random random = new Random();
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < length; i++) {
            do {
                int number = random.nextInt(base.length());
                sb.append(base.charAt(number));
            }while (stringList.contains(sb));
            stringList.add(String.valueOf(sb));
        }


//        System.out.println(sb);
        return sb.toString();
    }

    //添加十个的方法
    public void readd() {
        for (int j = 1; j <= 10; j++) {
            System.out.println("第" + j + "个随机字符串：" + getRandomString(10));
        }
        List<String> stringList = new ArrayList<String>();
        System.out.println("**********排序前***********");
        for (String string : stringList) {
            System.out.println("元素：" + getRandomString(10));
        }
        Collections.sort(stringList);
        System.out.println("**********排序后***********");
        for (String string : stringList) {
            System.out.println("元素：" + getRandomString(10));
        }

    }






    public static void main(String[] args) {
        Test t = new Test();
        t.readd();
    }
}
